extends IGuiable


class_name Dragable
"""
可拖放的UI适配
"""


## 拖拽控制
@export var controller: IDragController = null


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "controller": [IComponent.find_up.bind(self, func(x): return x is IDragController, controller)],
    }, super.__check_exports())

func __init_hooks() -> Dictionary:
    if controller == null:
        return {}
    return IComponent.merge({
        wrapper.mouse_entered: on_mouse_entered,
        wrapper.mouse_exited: on_mouse_exited,
    }, super.__init_hooks())

func on_mouse_entered() -> void:
    if controller.shared.is_dragging:
        controller.shared.to = wrapper

func on_mouse_exited() -> void:
    if controller.shared.is_dragging:
        controller.shared.to = null

func is_dragging() -> bool:
    return controller.shared.is_dragging

func on_gui_input(event: InputEvent) -> void:
    if not controller.shared.is_dragging and controller.is_start(event):
        controller.ready_to_drag(wrapper)
    if controller.shared.is_dragging:
        controller.on_mouse_dragging(event)
